home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / UTILREEN / ZENO21.LZH / ZENO21.ASM next >
Assembly Source File  |  1989-01-23  |  19KB  |  548 lines

  1. page ,132
  2. ;  X:0
  3. ;
  4. ; ZENO:  June 11, 1986
  5. ;
  6. ;   Modified Sept 4, 1986 by R Tansky to fix 40-character mode
  7. ;   Modified Oct 31, 1986 by R Tansky to further fix 40-character mode
  8. ;           and to fix graphics mode
  9. ;   Modified Jan 28, 1987 by C Blum to add code to support TTY mode
  10. ;           call ( AH=0EH ). Required by some clone BIOS implementations
  11. ;           ( DTK / ERSO for one ) because they do not issue any 'set
  12. ;           cursor' calls from within the TTY mode call. This causes
  13. ;           ZENO to lose its video offset and the display goes out to
  14. ;           lunch.
  15. ;   Modified May 29, 1987 by Lynn Ransdell to support KEDIT 3.51
  16. ;   Modified Dec 13, 1988 by Glenn K. Smith to do snow checking
  17. ;        and to add a /S option to enable this checking. This
  18. ;           causes ZENO to be around 2 1/2 times slower. (ZENOTEST=66 @10mhz)
  19. ;   Modified Jan 15, 1988 by Glenn K. Smith to speed up snow checking
  20. ;           and to fix a bug.  Some programs didn't work right with
  21. ;           ZENO. Mainly those which modified the cursor position without
  22. ;           calling ZENO. (Procomm+, Turbo Pascal CRT unit and others).
  23. ;        The fix required calculating the screen offset using the BIOS
  24. ;        cursor everytime a character was placed on the screen.
  25. ;        (ZENOTEST now takes 46 seconds @10mhz. A 20 second savings)
  26. ;
  27. ;
  28. cseg    segment para public 'code'
  29. zeno            proc  far
  30.         assume  cs:cseg, ds:cseg, es:cseg, ss:cseg
  31.         org     100h            ; for .COM file
  32. ;
  33. environment     equ   2Ch
  34. command         equ   80h
  35. slashk          equ   'K/'
  36. slashk2         equ   'k/'
  37. slashs        equ   'S/'
  38. slashs2            equ   's/'
  39. ;
  40. ;-------------------------------
  41. ; enter here on initial load
  42. ;-------------------------------
  43. ;
  44. start:
  45. ;
  46.         jmp     near ptr load_pgm
  47. ;
  48. video_vector    dd   0
  49. core_seg        dw   0
  50. ;
  51. bios_cursor_posn  label  dword
  52. bios_ofst       dw   00h        ; offset for active page
  53.                 dw   40h        ; segment for bios data
  54.  
  55. ;
  56. crt_mode        db   2          ; passes if 4, 5, or 6
  57. active_page     db   0
  58. cursor_type     dw   0B0Ch      ; DOS cursor
  59. ;
  60. video_posn      label  dword
  61. video_ofst      dw     0        ; offset against video_seg
  62. video_seg       dw     0
  63. ;
  64. video_addr      dw     0
  65. ;
  66. onesixty        db   160
  67. ;
  68. flag        db     0    ; Snow checking flag
  69. ;
  70. ;-------------------------------
  71. ; enter here from int 10h
  72. ;-------------------------------
  73. ;
  74. video_int:
  75.         sti                     ; interrupts on
  76.         pushf                   ; save flags
  77.         cmp     cs:crt_mode,3   ; check for color text 1
  78.         je      video_keep      ; go if so
  79.         cmp     cs:crt_mode,2   ; check for color text 2
  80.         je      video_keep      ; go if so
  81.         cmp     cs:crt_mode,7   ; check for b/w
  82.         je      video_keep      ; go if so
  83.         cmp     ah,0            ; to set mode
  84.         je      route_set_mode
  85.         jmp     video_exit      ; go if graphics / 40 col
  86. video_keep:
  87.         cmp     ah,14           ; to write as TTY
  88.         je      route_TTY
  89.         cmp     ah,2            ; to set cursor
  90.         je      route_set_cursor
  91.         cmp     ah,10           ; to write char only
  92.         je      write_char
  93.         cmp     ah,9            ; to write char/attr
  94.         je      route_write_both
  95.         cmp     ah,3            ; to read cursor
  96.         je      route_read_cursor
  97.         cmp     ah,1            ; to set type
  98.         je      route_set_type
  99.         cmp     ah,0            ; to set mode
  100.         je      route_set_mode
  101.         cmp     ah,5            ; to set page
  102.         je      route_set_page
  103.         cmp     ax,0FEFEh       ; kill code (FORMERLY 0FFOOh)
  104.         je      route_do_kill   ; go if found
  105. video_exit:
  106.         popf                    ; restore flags
  107.         jmp     cs:dword ptr video_vector ; hand off interrupt
  108. ;
  109. route_TTY:
  110.         jmp     TTY
  111. ;
  112. route_write_both:
  113.         jmp     write_both
  114. ;
  115. route_read_cursor:
  116.         jmp     read_cursor
  117. ;
  118. route_set_page:
  119.         jmp     set_page
  120. ;
  121. route_set_type:
  122.         jmp     set_type
  123. ;
  124. route_set_cursor:
  125.     jmp    set_cursor
  126. ;
  127. route_set_mode:
  128.         jmp     set_mode
  129. ;
  130. route_do_kill:
  131.         jmp     do_kill
  132.  
  133. ;
  134. write_char:
  135.         cmp     bh,cs:active_page ; check page
  136.         jne     video_exit      ; pass to bios
  137.         cmp     cx,1            ; for multiple write
  138.         jne     video_exit      ; pass to bios
  139.         push    di              ; save
  140.         push    es              ; save
  141.     push    ax
  142.     les    di,cs:bios_cursor_posn
  143.     mov    ax,es:[di]
  144.         mov     cx,ax           ; copy posn
  145.         mov     al,ah           ; rows in al
  146.         mul     cs:onesixty     ; for bytes
  147.         xor     ch,ch           ; cols in cx
  148.         shl     cx,1            ; for video
  149.         add     ax,cx           ; offset in ax
  150.         mov     cs:video_ofst,ax ; store offset
  151.     pop     ax
  152.         les     di,cs:video_posn ; get screen position
  153.     cmp    cs:flag,1
  154.     je    writ0
  155.     stosb
  156.     jmp    writ3
  157.  
  158. writ0:    push    dx            ; Put char without snow
  159.     mov    dx,03DAh
  160.     xchg    ah,al            ; Save char in AH for later use
  161.  
  162.     cli
  163. WaitNoH:
  164.     in      al, dx                  ; Get 6845 Status
  165.     test    al,8                    ; Check vert retrace
  166.     jnz     WaitE                   ;   In Progress? go
  167.     rcr     al,1                    ; Wait for end of
  168.     jc      WaitNoH                 ;   horizontial retrace
  169. WaitH:
  170.     in      al, dx                  ; Get 6845 status again
  171.     rcr     al, 1                   ; Wait for horizontial
  172.     jnc     WaitH                   ;   retrace
  173. WaitE:
  174.     xchg    ah,al
  175.     stosb
  176.     sti
  177.     pop    dx              ; restore
  178.  
  179. writ3:
  180.         pop     es              ; restore
  181.         pop     di              ; restore
  182.         popf                    ; restore flags
  183.         iret                    ; done
  184. ;
  185. set_cursor:
  186.         cmp     bh,cs:active_page ; check page
  187.         jne     video_exit      ; pass to bios
  188.         push    ax              ; save
  189.         push    cx              ; save
  190.         push    dx              ; save
  191.         push    di              ; save
  192.         push    es              ; save
  193. set_cursor_2:
  194.         add     cs:video_ofst,2 ; for next char
  195.         les     di,cs:bios_cursor_posn ; get bios
  196.         inc     byte ptr es:[di] ; assume next
  197.         cmp     es:[di],dx      ; check if next
  198.         je      offset_ready    ; go if next
  199.         mov     ax,dx           ; get req posn
  200.         mov     es:[di],ax      ; save req posn
  201.         mov     cx,ax           ; copy posn
  202.         mov     al,ah           ; rows in al
  203.         mul     cs:onesixty     ; for bytes
  204.         xor     ch,ch           ; cols in cx
  205.         shl     cx,1            ; for video
  206.         add     ax,cx           ; offset in ax
  207.         mov     cs:video_ofst,ax ; store offset
  208. offset_ready:
  209.         mov     cx,cs:video_ofst ; offset in cx
  210.         shr     cx,1            ; for byte count
  211.         mov     ah,14           ; cursor MSB register
  212.         mov     dx,cs:video_addr ; 6845 index addr
  213.         mov     al,ah           ; get register
  214.         out     dx,al           ; send register
  215.         inc     dx              ; 6845 data addr
  216.         mov     al,ch           ; get cursor MSB
  217.         out     dx,al           ; send cursor MSB
  218.         dec     dx              ; 6845 index addr
  219.         mov     al,ah           ; cursor MSB register
  220.         inc     al              ; cursor LSB register
  221.         out     dx,al           ; send register
  222.         inc     dx              ; 6845 data addr
  223.         mov     al,cl           ; get cursor LSB
  224.         out     dx,al           ; send cursor LSB
  225.         pop     es              ; restore
  226.         pop     di              ; restore
  227.         pop     dx              ; restore
  228.         pop     cx              ; restore
  229.         pop     ax              ; restore
  230.         popf                    ; restore flags
  231.         iret                    ; done
  232. ;
  233. write_both:
  234.         cmp     bh,cs:active_page ; check page
  235.         jne     route_video_exit ; pass to bios
  236.         cmp     cx,1            ; check multiple write
  237.         jne     route_video_exit ; pass to bios
  238.         push    ax              ; save
  239.         push    di              ; save
  240.         push    es              ; save
  241.         mov     ah,bl           ; get attribute
  242.     push    ax
  243.     les    di,cs:bios_cursor_posn
  244.     mov    ax,es:[di]
  245.         mov     cx,ax           ; copy posn
  246.         mov     al,ah           ; rows in al
  247.         mul     cs:onesixty     ; for bytes
  248.         xor     ch,ch           ; cols in cx
  249.         shl     cx,1            ; for video
  250.         add     ax,cx           ; offset in ax
  251.         mov     cs:video_ofst,ax ; store offset
  252.     pop    ax
  253.         les     di,cs:video_posn ; get screen position
  254.     cmp    cs:flag,1    ; Snow checking?
  255.     je    col
  256.     stosw            ; Place char+attr onto screen
  257.     jmp    col2
  258.  
  259. col:    push    dx
  260.     push    bx
  261. color:    mov    dx,03DAh
  262.     mov    bx,ax
  263.  
  264.     cli
  265. WaitNoH1:
  266.     in      al, dx                  ; Get 6845 Status
  267.     test    al,8                    ; Check vert retrace
  268.     jnz     WaitE1                  ;   In Progress? go
  269.     rcr     al,1                    ; Wait for end of
  270.     jc      WaitNoH1                ;   horizontial retrace
  271. WaitH1:
  272.     in      al, dx                  ; Get 6845 status again
  273.     rcr     al, 1                   ; Wait for horizontial
  274.     jnc     WaitH1                  ;   retrace
  275. WaitE1:
  276.     mov    ax,bx
  277.     stosw
  278.     sti
  279.     pop    bx        ; restore
  280.     pop    dx              ; restore
  281.  
  282. col2:   pop     es              ; restore
  283.         pop     di              ; restore
  284.         pop     ax              ; restore
  285.         popf                    ; restore flags
  286.         iret                    ; done
  287. ;
  288. route_video_exit:
  289.         jmp     video_exit
  290. ;
  291. read_cursor:
  292.         cmp     bh,cs:active_page ; check page
  293.         jne     route_video_exit ; pass to bios
  294.         push    di              ; save
  295.         push    es              ; save
  296.         les     di,cs:bios_cursor_posn ; get bios
  297.         mov     dx,es:[di]      ; get bios posn
  298.         mov     cx,cs:cursor_type ; get type
  299.         pop     es              ; restore
  300.         pop     di              ; restore
  301.         popf                    ; restore flags
  302.         iret                    ; done
  303. ;
  304. set_page:
  305.         push    ax              ; save
  306.         mov     cs:active_page,al ; save page
  307.         xor     ah,ah           ; page in ax
  308.         shl     ax,1            ; for word count
  309.         add     ax,50h          ; offset for page zero
  310.         mov     cs:bios_ofst,ax ; save offset
  311.         pop     ax              ; restore
  312.         jmp     video_exit      ; pass to bios
  313. ;
  314. set_type:
  315.         mov     cs:cursor_type,cx ; save type
  316.         jmp     video_exit      ; pass to bios
  317. ;
  318. set_mode:
  319.         mov     cs:crt_mode,al  ; save mode
  320.         mov     cs:video_ofst,0 ; top left
  321.         jmp     video_exit      ; done
  322. ;
  323. TTY:
  324.         cmp     bh,cs:active_page ; check page
  325.         jne     route_video_exit ; pass to bios
  326.         cmp     al,' '          ; control characters
  327.         jb      TTY_std         ;   go to real BIOS
  328.         cmp     cs:video_ofst,25*80*2-2 ; scroll imminent ?
  329.         jnb     TTY_std         ; yes, to real BIOS
  330.         push    ax              ; save
  331.         push    cx              ; save
  332.         push    dx              ; save
  333.         push    di              ; save
  334.         push    es              ; save
  335.     push    ax
  336.     les    di,cs:bios_cursor_posn
  337.     mov    ax,es:[di]
  338.         mov     cx,ax           ; copy posn
  339.         mov     al,ah           ; rows in al
  340.         mul     cs:onesixty     ; for bytes
  341.         xor     ch,ch           ; cols in cx
  342.         shl     cx,1            ; for video
  343.         add     ax,cx           ; offset in ax
  344.         mov     cs:video_ofst,ax ; store offset
  345.     pop    ax
  346.         les     di,cs:video_posn ; get screen pos
  347.     cmp    cs:flag,1    ; Snow checking?
  348.     je    tty0
  349.     stosb
  350.     jmp    tty1
  351.  
  352. tty0:    push    dx
  353.     mov    dx,03DAh
  354.     xchg    ah,al
  355.  
  356.     cli
  357. WaitNoH2:
  358.     in      al, dx                  ; Get 6845 Status
  359.     test    al,8                    ; Check vert retrace
  360.     jnz     WaitE2                  ;   In Progress? go
  361.     rcr     al,1                    ; Wait for end of
  362.     jc      WaitNoH2                ;   horizontial retrace
  363. WaitH2:
  364.     in      al, dx                  ; Get 6845 status again
  365.     rcr     al, 1                   ; Wait for horizontial
  366.     jnc     WaitH2                  ;   retrace
  367. WaitE2:
  368.     xchg    ah,al
  369.     stosb
  370.     sti
  371.     pop    dx
  372.  
  373. tty1:   les     di,cs:bios_cursor_posn ; get bios
  374.         mov     dx,es:[di]      ; get current pos
  375.         inc     dl              ; next char pos
  376.         cmp     dl,79           ; new line ?
  377.         ja      TTY_new_line    ; yes, adjust
  378.         jmp     set_cursor_2    ; set cursor
  379. TTY_new_line:
  380.         mov     dl,0            ; col = 1
  381.         inc     dh              ; inc row
  382.         jmp     set_cursor_2    ; set cursor
  383. TTY_std:
  384.         pushf                   ; phony int
  385.         call    cs:video_vector ;   to real bios
  386.         push    ax              ; save
  387.         push    bx              ; save
  388.         push    es              ; save
  389.     les    di,cs:bios_cursor_posn
  390.     mov    ax,es:[di]
  391.         mov     cx,ax           ; copy posn
  392.         mov     al,ah           ; rows in al
  393.         mul     cs:onesixty     ; for bytes
  394.         xor     ch,ch           ; cols in cx
  395.         shl     cx,1            ; for video
  396.         add     ax,cx           ; offset in ax
  397.         mov     cs:video_ofst,ax ; store offset
  398.         pop     es              ; restore
  399.         pop     bx              ; restore
  400.         pop     ax              ; restore
  401.         popf                    ; restore flags
  402.         iret                    ; done
  403. ;
  404. ; remove routine from memory
  405. ;
  406. do_kill:
  407.         mov     ax,cs           ; get code segment
  408.         mov     ds,ax           ; set data segment
  409.         mov     es,ax           ; set extra segment
  410.         push    ds              ; save
  411.         mov     ax,2510h        ; to set video vector
  412.         lds     dx,video_vector ; get original
  413.         int     21h             ; set vector
  414.         pop     ds              ; restore
  415.         mov     ah,49h          ; for free memory fn
  416.         int     21h             ; do free memory
  417.         push    es              ; save
  418.         mov     bx,environment  ; get env. segment
  419.         mov     es,cs:[bx]
  420.         mov     ah,49h          ; for free memory fn
  421.         int     21h             ; do free memory
  422.         pop     es              ; restore
  423.         lea     dx,kill_msg     ; get message
  424.         mov     ah,9            ; for screen write
  425.         int     21h             ; do write
  426.         popf                    ; restore flags
  427.         iret                    ; return to ZENO/K
  428. ;
  429. kill_msg        db   13,10,'ZENO Removed',13,10,'$'
  430. ;
  431. end_core:
  432. ;
  433. ;-------------------------------
  434. ; enter here to load program
  435. ;-------------------------------
  436. ;
  437. load_pgm:
  438. ;
  439. ; check for color screen; set video segment
  440. ;
  441.         mov     video_seg,0B000h ; assume mono
  442.         mov     video_addr,03B4h ; assume mono
  443.         int     11h             ; for equip check
  444.         and     ax,30h          ; isolate adapter
  445.         cmp     ax,30h          ; check for mono
  446.         je      mono_screen     ; go if found
  447.         mov     video_seg,0B800h ; reset for color
  448.         mov     video_addr,03D4h ; reset for color
  449. mono_screen:
  450. ;
  451. ; check command line
  452. ;
  453.         mov     si,command      ; get command line
  454.         mov     al,cs:[si]      ; length of argument
  455.         or      al,al           ; check for zero
  456.         je      command_clear   ; go if zero
  457.         cmp     al,2            ; for kill request
  458.         jne     retry           ; go if not
  459.     cmp    word ptr cs:[si+1],slashs2  ; check for '/s'
  460.     je    flake
  461.     cmp    word ptr cs:[si+1],slashs  ; check for '/S'
  462.     je    flake
  463.         cmp     word ptr cs:[si+1],slashk2 ; check for '/k'
  464.         je      killme          ; go if not
  465.         cmp     word ptr cs:[si+1],slashk ; check for '/K'
  466.         jne     retry           ; go if not
  467. killme: mov     ax,0FEFEh       ; set for kill (FORMERLY 0FFOOh)
  468.         int     10h             ; order kill
  469.         int     20h             ; exit to DOS
  470. retry:
  471.         lea     dx,retry_msg    ; get message
  472.         mov     ah,9            ; for print fn
  473.         int     21h             ; print message
  474.         int     20h             ; exit to DOS
  475.  
  476. flake:    inc    cs:flag        ; turn on snow checking
  477. command_clear:
  478. ;
  479. ; find and set current variables
  480. ;
  481.         les     di,bios_cursor_posn ; set to 0040:0000
  482.         mov     al,es:[di+49h]  ; get current mode
  483.         mov     crt_mode,al     ; save mode
  484.         mov     ax,es:[di+60h]  ; get cursor type
  485.         mov     cursor_type,ax  ; save type
  486.         mov     al,es:[di+62h]  ; get active page
  487.         mov     active_page,al  ; save active page
  488.         xor     ah,ah           ; page in ax
  489.         shl     ax,1            ; for word count
  490.         add     ax,50h          ; offset for page zero
  491.         mov     bios_ofst,ax    ; save offset
  492. ;
  493. ; set video interrupt
  494. ;
  495.         mov     core_seg,cs     ; set core segment
  496.         push    es              ; save
  497.         mov     ax,3510h        ; to get vector
  498.         int     21h             ; get vector
  499.         mov     word ptr video_vector,bx ; store offset
  500.         mov     word ptr video_vector+2,es ; store segment
  501.         pop     es              ; restore
  502.         mov     ax,2510h        ; to set video vector
  503.         lea     dx,video_int    ; get offset; ds OK
  504.         int     21h             ; set vector
  505. ;
  506. ; print messages; terminate and stay resident
  507. ;
  508.         lea     dx,install_msg  ; get message
  509.         mov     ah,9h           ; for print fn
  510.         int     21h             ; print message
  511.     cmp    cs:flag,1    ; check for snow flag
  512.     jne    seemon
  513.     lea    dx,snow_msg     ; get message
  514.     jmp    shmsg        ; show message
  515.  
  516. seemon: cmp     video_seg,0B000h ; check for mono
  517.         je      skip_message    ; go if mono
  518.         lea     dx,color_msg    ; get message
  519.  
  520. shmsg:  mov     ah,9h           ; for print fn
  521.         int     21h             ; print message
  522. skip_message:
  523.         lea     dx,finish_msg   ; get termination
  524.         mov     ah,9h           ; for print fn
  525.         int     21h             ; print ternination
  526.         lea     ax,end_core     ; last address in core
  527.         add     ax,2Fh          ; make bumper
  528.         mov     cl,4            ; for shift
  529.         shr     ax,cl           ; convert to paras
  530.         mov     bx,ax           ; no. paras to keep
  531.         mov     dx,ax           ; same
  532.         mov     ah,4Ah          ; for setblock
  533.         int     21h             ; do setblock
  534.         mov     ax,3100h        ; for keep; no exit code
  535.         int     21h             ; exit and stay resident
  536. ;
  537. install_msg     db   13,10,'ZENO 2.1 successfully Installed!',13,10,'$'
  538. snow_msg    db   13,10,'Snow checking enabled.',13,10,'$'
  539. color_msg    db   'If snow is present, re-install using the /S option.',13,10
  540. finish_msg      db   13,10,'$'
  541. ;
  542. retry_msg       db   13,10,'No Action:  Use /S or /K only!',13,10,7,'$'
  543. ;
  544. zeno            endp
  545. cseg            ends
  546.         end     start
  547.  
  548.